/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.quality4spl.fm.cvm.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EDataTypeEList;

import org.quality4spl.fm.cvm.CvmPackage;
import org.quality4spl.fm.cvm.FeatureModel;
import org.quality4spl.fm.cvm.FeatureModelPrototype;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Feature Model Prototype</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.quality4spl.fm.cvm.impl.FeatureModelPrototypeImpl#getPrototypeName <em>Prototype Name</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.FeatureModelPrototypeImpl#getPath <em>Path</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.FeatureModelPrototypeImpl#getType <em>Type</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class FeatureModelPrototypeImpl extends NamedElementImpl implements FeatureModelPrototype {
	/**
	 * The default value of the '{@link #getPrototypeName() <em>Prototype Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPrototypeName()
	 * @generated
	 * @ordered
	 */
	protected static final String PROTOTYPE_NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getPrototypeName() <em>Prototype Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPrototypeName()
	 * @generated
	 * @ordered
	 */
	protected String prototypeName = PROTOTYPE_NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getPath() <em>Path</em>}' attribute list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPath()
	 * @generated
	 * @ordered
	 */
	protected EList<String> path;

	/**
	 * The cached value of the '{@link #getType() <em>Type</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getType()
	 * @generated
	 * @ordered
	 */
	protected FeatureModel type;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected FeatureModelPrototypeImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return CvmPackage.Literals.FEATURE_MODEL_PROTOTYPE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getPrototypeName() {
		return prototypeName;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPrototypeName(String newPrototypeName) {
		String oldPrototypeName = prototypeName;
		prototypeName = newPrototypeName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CvmPackage.FEATURE_MODEL_PROTOTYPE__PROTOTYPE_NAME, oldPrototypeName, prototypeName));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<String> getPath() {
		if (path == null) {
			path = new EDataTypeEList<String>(String.class, this, CvmPackage.FEATURE_MODEL_PROTOTYPE__PATH);
		}
		return path;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public FeatureModel getType() {
		if (type != null && type.eIsProxy()) {
			InternalEObject oldType = (InternalEObject)type;
			type = (FeatureModel)eResolveProxy(oldType);
			if (type != oldType) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, CvmPackage.FEATURE_MODEL_PROTOTYPE__TYPE, oldType, type));
			}
		}
		return type;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public FeatureModel basicGetType() {
		return type;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setType(FeatureModel newType) {
		FeatureModel oldType = type;
		type = newType;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CvmPackage.FEATURE_MODEL_PROTOTYPE__TYPE, oldType, type));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case CvmPackage.FEATURE_MODEL_PROTOTYPE__PROTOTYPE_NAME:
				return getPrototypeName();
			case CvmPackage.FEATURE_MODEL_PROTOTYPE__PATH:
				return getPath();
			case CvmPackage.FEATURE_MODEL_PROTOTYPE__TYPE:
				if (resolve) return getType();
				return basicGetType();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case CvmPackage.FEATURE_MODEL_PROTOTYPE__PROTOTYPE_NAME:
				setPrototypeName((String)newValue);
				return;
			case CvmPackage.FEATURE_MODEL_PROTOTYPE__PATH:
				getPath().clear();
				getPath().addAll((Collection<? extends String>)newValue);
				return;
			case CvmPackage.FEATURE_MODEL_PROTOTYPE__TYPE:
				setType((FeatureModel)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case CvmPackage.FEATURE_MODEL_PROTOTYPE__PROTOTYPE_NAME:
				setPrototypeName(PROTOTYPE_NAME_EDEFAULT);
				return;
			case CvmPackage.FEATURE_MODEL_PROTOTYPE__PATH:
				getPath().clear();
				return;
			case CvmPackage.FEATURE_MODEL_PROTOTYPE__TYPE:
				setType((FeatureModel)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case CvmPackage.FEATURE_MODEL_PROTOTYPE__PROTOTYPE_NAME:
				return PROTOTYPE_NAME_EDEFAULT == null ? prototypeName != null : !PROTOTYPE_NAME_EDEFAULT.equals(prototypeName);
			case CvmPackage.FEATURE_MODEL_PROTOTYPE__PATH:
				return path != null && !path.isEmpty();
			case CvmPackage.FEATURE_MODEL_PROTOTYPE__TYPE:
				return type != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (prototypeName: ");
		result.append(prototypeName);
		result.append(", path: ");
		result.append(path);
		result.append(')');
		return result.toString();
	}

} //FeatureModelPrototypeImpl
